package model;

import java.time.LocalDateTime;

/**
 * 信誉分记录实体类
 */
public class CreditLog {
    private int logId;
    private int userId;
    private int attendanceId;
    private int scoreChange;
    private int scoreAfter;
    private String reason;
    private int logType; // 1-考勤相关，2-管理员调整，3-系统奖励
    private LocalDateTime createTime;

    // 关联对象
    private User user;
    private AttendanceRecord attendanceRecord;

    public CreditLog() {
    }

    public CreditLog(int userId, int scoreChange, int scoreAfter, String reason, int logType) {
        this.userId = userId;
        this.scoreChange = scoreChange;
        this.scoreAfter = scoreAfter;
        this.reason = reason;
        this.logType = logType;
        this.createTime = LocalDateTime.now();
    }

    public CreditLog(int userId, int attendanceId, int scoreChange, int scoreAfter, String reason, int logType) {
        this.userId = userId;
        this.attendanceId = attendanceId;
        this.scoreChange = scoreChange;
        this.scoreAfter = scoreAfter;
        this.reason = reason;
        this.logType = logType;
        this.createTime = LocalDateTime.now();
    }

    // Getters and Setters
    public int getLogId() {
        return logId;
    }

    public void setLogId(int logId) {
        this.logId = logId;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getAttendanceId() {
        return attendanceId;
    }

    public void setAttendanceId(int attendanceId) {
        this.attendanceId = attendanceId;
    }

    public int getScoreChange() {
        return scoreChange;
    }

    public void setScoreChange(int scoreChange) {
        this.scoreChange = scoreChange;
    }

    public int getScoreAfter() {
        return scoreAfter;
    }

    public void setScoreAfter(int scoreAfter) {
        this.scoreAfter = scoreAfter;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public int getLogType() {
        return logType;
    }

    public void setLogType(int logType) {
        this.logType = logType;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public AttendanceRecord getAttendanceRecord() {
        return attendanceRecord;
    }

    public void setAttendanceRecord(AttendanceRecord attendanceRecord) {
        this.attendanceRecord = attendanceRecord;
    }

    // 工具方法
    public String getLogTypeText() {
        switch (logType) {
            case 1:
                return "考勤相关";
            case 2:
                return "管理员调整";
            case 3:
                return "系统奖励";
            default:
                return "未知类型";
        }
    }

    public String getScoreChangeText() {
        if (scoreChange > 0) {
            return "+" + scoreChange;
        } else {
            return String.valueOf(scoreChange);
        }
    }

    public boolean isPositiveChange() {
        return scoreChange > 0;
    }

    public boolean isNegativeChange() {
        return scoreChange < 0;
    }
}
